Matrix


Problem 1
Create an Open GL application called Yellow to test translation in Open GL.
Cree una aplicación de Open GL llamada Yellow para probar la translación en Open GL.

YellowRun1

YellowRun2

Yellow.cpp
...
bool Yellow::RenderScene()
{
     static double currentTime = 0.0;
     //_________________________________________________ Translation
     static double z = 0.0;
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);// clear screen and depth buffer
     glLoadIdentity();
     gluLookAt(0.0f, 6.0f, 0.1f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);
     glPushMatrix();
     glTranslatef(0.0f, 0.0f, (GLfloat)z);
     glPointSize(4);
     glBegin(GL_POINTS);
     glVertex3f(5.0f, 0.0f, 0.0f);
     glEnd();
     glPopMatrix();
     const double deltaTime = stopWatch.GetSeconds() - currentTime;
     z -= (deltaTime*0.1f);
     currentTime = stopWatch.GetSeconds() ;
     return true; // return false to stop
}


Problem 2
Create an Open GL application called Purple to test rotation in Open GL.
Cree una aplicación de Open GL llamada Purple para probar la rotación en Open GL.

PurpleRun1

PurpleRun2

Purple.cpp
...
bool Purple::RenderScene()
{
     static double currentTime = 0.0;
     //________________________________________________ Rotation X
     static double angle = 0.0f;
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);// clear screen and depth buffer
     glLoadIdentity();
     gluLookAt(0.0f, 10.0f, 0.1f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);     
     glColor3f(0.0f, 1.0f, 0.0f);
     glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
     glPushMatrix();
     glRotatef((float)angle, 1.0f, 0.0f, 0.0f);
     //________________________________________________ Draw Cube
     glBegin(GL_POLYGON);
     //_________________________ top face
     glVertex3f(0.0f, 0.0f, 0.0f);
     glVertex3f(0.0f, 0.0f, -1.0f);
     glVertex3f(-1.0f, 0.0f, -1.0f);
     glVertex3f(-1.0f, 0.0f, 0.0f);
     //_________________________ front face
     glVertex3f(0.0f, 0.0f, 0.0f);
     glVertex3f(-1.0f, 0.0f, 0.0f);
     glVertex3f(-1.0f, -1.0f, 0.0f);
     glVertex3f(0.0f, -1.0f, 0.0f);
     //_________________________ right face
     glVertex3f(0.0f, 0.0f, 0.0f);
     glVertex3f(0.0f, -1.0f, 0.0f);
     glVertex3f(0.0f, -1.0f, -1.0f);
     glVertex3f(0.0f, 0.0f, -1.0f);
     //_________________________ left face
     glVertex3f(-1.0f, 0.0f, 0.0f);
     glVertex3f(-1.0f, 0.0f, -1.0f);
     glVertex3f(-1.0f, -1.0f, -1.0f);
     glVertex3f(-1.0f, -1.0f, 0.0f);
     //_________________________ bottom face
     glVertex3f(0.0f, 0.0f, 0.0f);
     glVertex3f(0.0f, -1.0f, -1.0f);
     glVertex3f(-1.0f, -1.0f, -1.0f);
     glVertex3f(-1.0f, -1.0f, 0.0f);
     //_________________________ back face
     glVertex3f(0.0f, 0.0f, 0.0f);
     glVertex3f(-1.0f, 0.0f, -1.0f);
     glVertex3f(-1.0f, -1.0f, -1.0f);
     glVertex3f(0.0f, -1.0f, -1.0f);
     glEnd();

     glPopMatrix();
     const double deltaTime = stopWatch.GetSeconds() - currentTime;
     angle += deltaTime*20.0;
     if (angle > 360.0f) angle -= 360.0f;
     currentTime = stopWatch.GetSeconds();
     return true; // return false to stop
}


Problem 3
Create an Open GL application called Redy to test scaling in Open GL.
Cree una aplicación de Open GL llamada Redy para probar el escalamiento en Open GL.

RedyRun1

RedyRun2

Redy.cpp
...
bool Redy::RenderScene()
{
     static double currentTime = 0.0;
     //_______________________________________________ Scaling
     static double scale = 0.1;
     glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);// clear screen and depth buffer
     glLoadIdentity();
     gluLookAt(0.0, 10.0, 0.1, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
     glColor3f(0.0f, 1.0f, 0.0f);
     glPushMatrix();
     glRotatef(45, 1.0, 0.0, 0.0);
     glScalef((GLfloat)scale, (GLfloat)scale, (GLfloat)scale);
     //______________________________________________ Draw Cube
     glBegin(GL_POLYGON);
     //_________________________ top face
     glVertex3f(0.0f, 0.0f, 0.0f);
     glVertex3f(0.0f, 0.0f, -1.0f);
     glVertex3f(-1.0f, 0.0f, -1.0f);
     glVertex3f(-1.0f, 0.0f, 0.0f);
     //_________________________ front face
     glVertex3f(0.0f, 0.0f, 0.0f);
     glVertex3f(-1.0f, 0.0f, 0.0f);
     glVertex3f(-1.0f, -1.0f, 0.0f);
     glVertex3f(0.0f, -1.0f, 0.0f);
     //_________________________ right face
     glVertex3f(0.0f, 0.0f, 0.0f);
     glVertex3f(0.0f, -1.0f, 0.0f);
     glVertex3f(0.0f, -1.0f, -1.0f);
     glVertex3f(0.0f, 0.0f, -1.0f);
     //_________________________ left face
     glVertex3f(-1.0f, 0.0f, 0.0f);
     glVertex3f(-1.0f, 0.0f, -1.0f);
     glVertex3f(-1.0f, -1.0f, -1.0f);
     glVertex3f(-1.0f, -1.0f, 0.0f);
     //_________________________ bottom face
     glVertex3f(0.0f, 0.0f, 0.0f);
     glVertex3f(0.0f, -1.0f, -1.0f);
     glVertex3f(-1.0f, -1.0f, -1.0f);
     glVertex3f(-1.0f, -1.0f, 0.0f);
     //_________________________ back face
     glVertex3f(0.0f, 0.0f, 0.0f);
     glVertex3f(-1.0f, 0.0f, -1.0f);
     glVertex3f(-1.0f, -1.0f, -1.0f);
     glVertex3f(0.0f, -1.0f, -1.0f);
     glEnd();

     glPopMatrix();
     const double deltaTime = stopWatch.GetSeconds() - currentTime;
     scale += (deltaTime*0.1f);
     if (scale > 3.0) scale = 0.0f;
     currentTime = stopWatch.GetSeconds();
     return true; // return false to stop
}



© Copyright 2000-2021 Wintempla selo. All Rights Reserved. Jul 22 2021. Home